package cn.iocoder.yudao.module.member.address.dal.mysql;

import cn.iocoder.yudao.framework.business.basic.dao.mapper.CoreMapper;
import cn.iocoder.yudao.framework.business.basic.dao.query.CoreLambdaQueryWrapper;
import cn.iocoder.yudao.module.member.address.dal.dataobject.MemberAddressDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface MemberAddressMapper extends CoreMapper<MemberAddressDO> {

    default MemberAddressDO selectByIdAndUserId(Long id, Long userId) {
        return selectOne(MemberAddressDO::getId, id, MemberAddressDO::getUserId, userId);
    }

    default List<MemberAddressDO> selectListByUserId(Long userId) {
        return selectList(new CoreLambdaQueryWrapper<MemberAddressDO>()
                .eq(MemberAddressDO::getUserId, userId)
                .orderByDesc(MemberAddressDO::getDefaultStatus));
    }

    default MemberAddressDO selectByUserIdAndDefaultStatus(Long userId) {
        return selectOne(new CoreLambdaQueryWrapper<MemberAddressDO>()
                .eq(MemberAddressDO::getUserId, userId)
                .orderByDesc(MemberAddressDO::getDefaultStatus));
    }

    default MemberAddressDO selectByUserIdAndIsDine(Long userId) {
        return selectOne(new CoreLambdaQueryWrapper<MemberAddressDO>()
                .eq(MemberAddressDO::getUserId, userId)
                .eq(MemberAddressDO::getIsDine, true));
    }

    default void deleteByUserId(Long userId) {
        delete(new CoreLambdaQueryWrapper<MemberAddressDO>()
                .eq(MemberAddressDO::getUserId, userId));
    }

}
